/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var searchInsert = function(nums, target) {
    var index = nums.indexOf(target);
    if(index != -1){
        return index
    }else{
        for ( var i=0;i<nums.length;i++ ){
            if(nums[i] < target && nums.length == i + 1){
                return i+1
            }else if(nums[i] < target && nums[i+1] > target){
                return i+1
            }else if (nums[0] > target ){
                return 0
            }
        }
    }
};

var result1 = searchInsert([1,3,5,6], 7)
var result2 = searchInsert([1,3,5,6], 2)